import { observable, action } from 'mobx';
import ListBaseStore from './ListBaseStore';
import * as CollectApis from '../apis/hrmview';
import { WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;

/**
 * 参与的协作Store
 */
export default class HrmViewStore extends ListBaseStore {
	status = {
		searchHrmid: '',
	  }

	constructor() {
		super();
		this.title = getLabel(83226, '参与的协作');
  }
  @observable isMe = false;

	@action doInit = (params) => {
		this.doBaseInit();
    	this.doTableLoading(params); // 初始化列表
  		this.initConditionDatas(); // 初始化高级搜索区域
	}

	// 加载列表数据
	@action doTableLoading = (params) => {
		this.showLoading(true);
		let resultParams = this.getFormParams();
		let commonParams = {};
		/*  两种写法都行
		resultParams = Object.assign(resultParams,{
			searchHrmid:this.status.searchHrmid,
		})  */

		resultParams = { searchHrmid: this.status.searchHrmid, ...resultParams, ...commonParams, ...params };
		CollectApis.getCoworkHrmViewList(resultParams).then(
			(result) => {
				const sessionkey = result.sessionkey;
				this.sessionkey = sessionkey;
				this.comsWeaTableStore.getDatas(sessionkey, 1);

				this.showLoading(false);
			},
		);
	}

	// 初始化参与的协作页面查询条件
	@action initConditionDatas = (params) => {
		CollectApis.getCoworkHrmViewShareCondition(params).then(
			(result) => {
				this.conditioninfo = result.conditioninfo;

				this.initFormFields(this.conditioninfo); // 一定要先初始化initFormFields表单对象
			},
		);
  }

  @action getUserInfo = (searchHrmid) => {
    this.isMe = false;
    CollectApis.getUserInfo().then((res) => {
      if (searchHrmid * 1 === res.user.id * 1) this.isMe = true;
      else this.isMe = false;
    });
  }


	setState = (params = {}) => {
		Object.keys(params).forEach((key) => {
		  this.status[key] = params[key];
		});
		return this;
	}
}
